package com.iddaa.core.dao.impl;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.stereotype.Repository;

import com.iddaa.core.dao.AccountDAO;
import com.iddaa.core.domain.Account;

@Repository("accountDao")
public class AccountDAOImpl extends AbstractHibernateDAO<Account, Long> implements AccountDAO {

	@SuppressWarnings("unchecked")
	@Override
	public Account authentication(String username, String password) {
		DetachedCriteria criteria = DetachedCriteria.forClass(persistentClass);
		criteria.add(Restrictions.eq("username", username));
		criteria.add(Restrictions.eq("password", password));
		return (Account) DataAccessUtils.uniqueResult(hibernateTemplate.findByCriteria(criteria));
	}

}
